//
//  ZJSCQusetOptionView.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJSCQusetOptionView.h"

@interface ZJSCQusetOptionView ()
/** 选项 */
@property (nonatomic, strong) UILabel *titleLabel;
/** 题目标号 */
@property (nonatomic, strong) UILabel *titleNumber;
/** 选中图标 */
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation ZJSCQusetOptionView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.imageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.titleNumber];
        self.isSelect = NO;
        
        self.imageView.sd_layout
        .rightSpaceToView(self, 12 * [UIScreen zj_screenWScale])
        .widthIs(22 * [UIScreen zj_screenWScale])
        .heightEqualToWidth()
        .centerYEqualToView(self);
        
        self.titleLabel.sd_layout
        .centerYEqualToView(self)
        .leftSpaceToView(self, 35 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 81 *[UIScreen zj_screenWScale])
        .heightIs(10);
        
        self.titleNumber.sd_layout
        .topEqualToView(self.titleLabel)
        .leftSpaceToView(self, 12 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self.titleLabel, 0)
        .heightIs([NSString heightWithTextFontSize:[UIFont titleTextFontSize]]);
        
        self.titleNumber.text = @"1、";
        
        UITapGestureRecognizer *tapgest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(action_click)];
        [self addGestureRecognizer: tapgest];
        
    }
    return self;
}

- (void)setString:(NSString *)string{
    _string = string;
    self.titleLabel.text = string;
    
    [self.titleLabel setLabelSpace:5 * [UIScreen zj_screenHScale]];
    CGFloat height = [self.titleLabel getSpaceLabelHeightFromSpace:5 * [UIScreen zj_screenHScale]];
    CGFloat  selfheight = height > 44 * [UIScreen zj_screenHScale] ? height + 16 * [UIScreen zj_screenHScale] : 60 * [UIScreen zj_screenHScale];
    self.titleLabel.height = height;
    self.height = selfheight;
    
    self.titleLabel.sd_layout
    .centerYEqualToView(self)
    .leftSpaceToView(self, 35 * [UIScreen zj_screenWScale])
    .widthIs([UIScreen zj_screenWith] - 81 *[UIScreen zj_screenWScale])
    .heightIs(height);
    [self.titleLabel updateLayout];
    
}

#pragma mark - 点击事件
- (void)action_click{
    self.isSelect = !self.isSelect;
    if (self.delegate) {
        [self.delegate ZJSCQusetOptionViewDelegate_selectClick:self];
    }
}


#pragma mark - Setter
- (void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    if (isSelect) {
        self.imageView.hidden = NO;
    }else{
        self.imageView.hidden = YES;
    }
}
#pragma mark - Getters

- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.backgroundColor = [UIColor randomColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.textColor = [UIColor textBlackColor];
        
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}
- (UILabel *)titleNumber{
    if (_titleNumber == nil){
        _titleNumber = [[UILabel alloc] init];
        _titleNumber.backgroundColor = [UIColor randomColor];
        _titleNumber.font = [UIFont titleTextFont];
        _titleNumber.textColor = [UIColor textBlackColor];
        
    }
    return _titleNumber;
}

- (UIImageView *)imageView{
    if (_imageView == nil){
        _imageView = [UIImageView new];
        _imageView.image = [UIImage imageNamed:@"learn_source_question_h"];
        _imageView.contentMode = UIViewContentModeRight;
        
    }
    return _imageView;
}

@end
